# _*_ coding: utf-8 _*_
# @Time     : 2022/7/16 9:47
# @Author   : dake
# @Email    : dake@2545923.com
# @File     : tjfx_kh.py
# @Software : PyCharm

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
import unittest
from selenium.webdriver.support.select import Select
import datetime

class KeHuTongJi(BasePage):
    """客户页面统计分析类"""
    url = "http://192.168.1.5:8081/crm/index.php?m=customer&a=analytics"  # 客户统计页面url
    table = "table table-hover table-striped"  # 断言统计报表使用
    laiyuan = "客户来源统计"  # 断言来源统计按钮
    qingkuang = "客户员工数统计"  # 客户情况统计
    hangye = "客户行业统计"
    seek = "admin"
    times = "2022-07-10 12:23:25"
    now_time = datetime.datetime.now()  # 算当前日期后一天的时间
    now = (now_time + datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
    """定位器"""
    show_report_locator = (By.ID, "show_report")  # 客户统计报表
    show_source_locator = (By.ID, "show_source")  # 来源统计报表
    show_scale_locator = (By.ID, "show_scale")  # 客户统计情况
    show_industry_locator = (By.ID, "show_industry")  # 客户行业统计
    table_locator = (By.XPATH, "//*[@id='report_content']/table")  # 表格的定位
    laiyuan_locator = (By.CSS_SELECTOR, "#highcharts-0 > svg > text.highcharts-title")  # 断言统计的定位
    qingkuang_locator = (By.CSS_SELECTOR, "#highcharts-4 > svg > text.highcharts-title")  # 断言客户情况统计用
    hangye_locator = (By.CSS_SELECTOR, '#highcharts-6 > svg > text.highcharts-title')
    department_locator = (By.NAME, "department")  # 定位选择部门下拉框
    role_locator = (By.NAME, "role")  # 选择员工下拉框
    start_time_locator = (By.NAME, "start_time")  # 开始时间
    end_time_locator = (By.NAME, "end_time")  # 结束时间
    submit_btn_locator = (By.CSS_SELECTOR, "#searchForm > ul > li:nth-child(4) > button")  # 搜索框
    admin_locator = (By.CSS_SELECTOR, "#report_content > table > tbody > tr > td:nth-child(1) > a")

    def click_show_report(self):
        """点击客户统计报表"""
        self.driver.find_element(*self.show_report_locator).click()

    def click_show_source(self):
        """点击来源统计报表"""
        self.driver.find_element(*self.show_source_locator).click()

    def click_show_scale(self):
        """点击客户统计情况"""
        self.driver.find_element(*self.show_scale_locator).click()

    def click_show_industry(self):
        """点击客户行业统计"""
        self.driver.find_element(*self.show_industry_locator).click()

    def get_cla(self):
        """获取切换到客户统计报表页面的元素的class"""
        return self.driver.find_element(*self.table_locator).get_attribute("class")

    def get_text1(self):
        """获取当前页面的判断切换到来源统计的元素的文本"""
        return self.driver.find_element(*self.laiyuan_locator).text

    def get_text2(self):
        """获取当前页面的判断切换到客户统计的元素的文本"""
        return self.driver.find_element(*self.qingkuang_locator).text

    def get_text3(self):
        """获取当前页面的判断切换到客户行业统计的元素的文本"""
        return self.driver.find_element(*self.hangye_locator).text

    def department_clic(self):
        """选择部门索引为一的点击"""
        Select(self.driver.find_element(*self.department_locator)).select_by_index(1)

    def role_clic(self):
        """选择员工"""
        Select(self.driver.find_element(*self.role_locator)).select_by_index(1)

    def start_time_input(self):
        """输入开始时间"""
        js = "document.getElementById('start_time').removeAttribute('readonly')"
        self.driver.execute_script(js)
        self.driver.find_element(*self.start_time_locator).send_keys(self.times)

    def end_time_input(self):
        """输入结束时间"""
        js = "document.getElementById('end_time').removeAttribute('readonly')"
        self.driver.execute_script(js)
        self.driver.find_element(*self.end_time_locator).send_keys(self.now)

    def submit_btn_clic(self):
        """点击搜索"""
        self.driver.find_element(*self.submit_btn_locator).click()

    def admin_site(self):
        """返回admin的a标签文本信息"""
        return self.driver.find_element(*self.admin_locator).text


if __name__ == "__main__":
    unittest.main()

